<template>
    <div>
        <el-form :model="formData" label-position="right" label-width="80px">
            <el-form-item label="品牌或厂家:">
                <el-input v-model="formData.brand" clearable placeholder="请输入" ></el-input>
            </el-form-item>

            <el-form-item label="品类名:"><el-input v-model.number="formData.cProduct" clearable placeholder="请输入"></el-input>
            </el-form-item>

            <el-form-item label="行业:"><el-input v-model.number="formData.cWork" clearable placeholder="请输入"></el-input>
            </el-form-item>

            <el-form-item label="内容:">
                <el-input v-model="formData.content" clearable placeholder="请输入" ></el-input>
            </el-form-item>

            <el-form-item label="是否质保:">
                <el-switch active-color="#13ce66" inactive-color="#ff4949" active-text="是" inactive-text="否" v-model="formData.isQa" clearable ></el-switch>
            </el-form-item>

            <el-form-item label="规格或型号:">
                <el-input v-model="formData.norms" clearable placeholder="请输入" ></el-input>
            </el-form-item>

            <el-form-item label="副标题:">
                <el-input v-model="formData.sTitle" clearable placeholder="请输入" ></el-input>
            </el-form-item>

            <el-form-item label="状态:"><el-input v-model.number="formData.status" clearable placeholder="请输入"></el-input>
            </el-form-item>

            <el-form-item label="仓库信息:">
                <el-input v-model="formData.stock" clearable placeholder="请输入" ></el-input>
            </el-form-item>

            <el-form-item label="标题:">
                <el-input v-model="formData.title" clearable placeholder="请输入" ></el-input>
            </el-form-item>

            <el-form-item label="用户编号:"><el-input v-model.number="formData.userId" clearable placeholder="请输入"></el-input>
            </el-form-item>
            <el-form-item>
                <el-button @click="save" type="primary">保存</el-button>
                <el-button @click="back" type="primary">返回</el-button>
            </el-form-item>
        </el-form>
    </div>
</template>

<script>
    import {
        createUserGoods,
        updateUserGoods,
        findUserGoods
    } from "@/api/userGoods";  //  此处请自行替换地址
    import infoList from "@/mixins/infoList";
    export default {
        name: "UserGoods",
        mixins: [infoList],
        data() {
            return {
                type: "",formData: {
                    brand:"",
                    cProduct:0,
                    cWork:0,
                    content:"",
                    isQa:false,
                    norms:"",
                    sTitle:"",
                    status:0,
                    stock:"",
                    title:"",
                    userId:0,

                }
            };
        },
        methods: {
            async save() {
                let res;
                switch (this.type) {
                    case "create":
                        res = await createUserGoods(this.formData);
                        break;
                    case "update":
                        res = await updateUserGoods(this.formData);
                        break;
                    default:
                        res = await createUserGoods(this.formData);
                        break;
                }
                if (res.code == 0) {
                    this.$message({
                        type:"success",
                        message:"创建/更改成功"
                    })
                }
            },
            back(){
                this.$router.go(-1)
            }
        },
        async created() {
            // 建议通过url传参获取目标数据ID 调用 find方法进行查询数据操作 从而决定本页面是create还是update 以下为id作为url参数示例
            if(this.$route.query.id){
                const res = await findUserGoods({ ID: this.$route.query.id })
                if(res.code == 0){
                    this.formData = res.data.reuserGoods
                    this.type = "update"
                }
            }else{
                this.type = "create"
            }

        }
    };
</script>

<style>
</style>
